import wx
import os
import suffix
import random




class FileDrop(wx.FileDropTarget):
    def __init__(self,windows):
        wx.FileDropTarget.__init__(self)
        self.windows = windows

    def OnDropFiles(self, x, y, filePath):
        if filePath:
            print(filePath,self.windows)
            for i in filePath:
                name = os.path.basename(i)
                obj, _type = suffix.ux_suffix(i)
                self.windows.mAddPage(obj(self.windows, i, _type), name)
            return True
        else:
            return False


class myNewbook(wx.Dialog):
    def __init__(self, value, msg, *a, **k):
        wx.Dialog.__init__(self, *a, **k)
        self.text = wx.TextCtrl(self)
        self.ok = wx.Button(self, wx.ID_OK)
        self.ok.SetDefault()
        self.cancel = wx.Button(self, wx.ID_CANCEL)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer1 = wx.BoxSizer(wx.VERTICAL)
        sizer2 = wx.BoxSizer(wx.HORIZONTAL)
        sizer2.Add(self.ok, wx.SizerFlags().Border().Center())
        sizer2.Add(self.cancel, wx.SizerFlags().Border().Center())
        sizer1.Add(wx.StaticText(self, label=value), wx.SizerFlags().Border().Center())
        sizer1.Add(self.text, wx.SizerFlags().Border().Center())
        sizer1.Add(sizer2, wx.SizerFlags().Border().Center())
        sizer.Add(sizer1, wx.SizerFlags(1).Border().Center())
        self.SetSizer(sizer)
        self.Layout()
        self.Centre( wx.BOTH )
        self.SetSizer(sizer)
        self.ok.Bind(wx.EVT_BUTTON, lambda evt, value=msg : self.on_click(evt, value))

    def on_click(self, eve, msg):
        if self.text.GetValue():
            eve.Skip()
        else:
            wx.MessageBox(msg, "提示", wx.CANCEL, self)



def myMenu(parent, menu, array):
    res_array = ()
    def bind(k,menobj):
        parent.Bind(wx.EVT_MENU, lambda eve, menu=k : parent.on_menu(eve, k), menobj)
    for k,v in enumerate(array):
        menobj = menu.Append(-1, v)
        bind(k,menobj)
        res_array = res_array.__add__((menobj,))
    return res_array


